﻿@model ConferenceMailModel
@{
	ViewBag.Title = Resources.ConferenceMail + ConstValues.strDash + ViewBag.ConferenceName;
}
<div id="dataGrid"></div>

@section bodyParts {
<div id="detailWindow" class="easyui-window"
	title="@Resources.ConferenceMail" data-options="closed:true,minimizable:false,iconCls:'icon-save'"
	style="width:1200px; display:none;">
	<div class="main">
		<div class="box clearfix">
			<h3 id="detailWindowTitle" class="tit01">@Resources.Preview</h3>
			<span id="ctnForm"></span>
			<h3 id="detailWindowTitle" class="tit01">@Resources.Edit</h3>
			<form id="frmDetail" method="post" enctype="multipart/form-data">
				@Html.AntiForgeryToken()
				<table width="100%" height="100%" id="tblDetail" cellpadding="0" cellspacing="1" border="0" class="tastyle01">
					<tr>
						<td style="text-align: right; " class="w1 c1">@Resources.CustomContent：</td>
						<td style="text-align: left;" class="w10 c2">
							<input type="hidden" id="hidId" name="MailId" />
							<input type="hidden" id="hidConferenceId" name="ConferenceId" />
							<input type=hidden id="txtCustomDefinition" name="CustomDefinition" />
							<div class="grid-container">
								<div class="grid-width-100" style="padding-left:0%;padding-right:0%;width:88%;">
									<textarea id="editor" name="editor"></textarea>
								</div>
							</div>
						</td>
					</tr>
				</table>
			</form>
			<div class="btnDiv">
				<input type="button" class="gbtn" onclick="saveData();" value="@Resources.Save" />&nbsp;&nbsp;
				<input type="button" class="rbtn" onclick="$('#detailWindow').window('close');" value="@Resources.Cancel" />
			</div>
		</div>
	</div>
</div>
}

@section Scripts {
<script>
	common.setCurrentMenu("ConferenceMail");
	common.setCurrentParentMenu("#menu_a6");

	var language = "@ViewBag.Language";
	if (language == "@ConstValues.Language.Cn") {
		CKEDITOR.config.language = "zh-cn";
	} else {
		CKEDITOR.config.language = "en";
	}

	initSample();

	$(function () {
		$("#hidConferenceId").val("@Model.ConferenceId");

		$("#dataGrid").datagrid({
			url: "@Url.Action(nameof(ConferenceMailController.GetData),nameof(ConferenceMailController).GetControllerName(),new { ConferenceId = Model.ConferenceId })",
			method: "get",
			singleSelect: true,
			fitColumns: true,
			width: $(window).width() - 285,
			height: $(window).height() - 123,
			nowrap: false,
			pagination: true,
			pageSize: @ConstValues.DefaultGridRows,
			striped: true,
			toolbar: "#toolBar",
			pageSize: 100,
			pageList: [100, 200, 300, 400, 500],
			columns: [[
				{ field: "id", hidden: true },
				@if ((User as ICISPrincipal).IsSSA || (User as ICISPrincipal).CSAList.Contains(Model.ConferenceId) ||
					Utility.HasConferenceRole((User as ICISPrincipal), Model.ConferenceId, ConstValues.FunctionId.ConferenceMail, RoleType.修改))
				{
					<text>
					{
						field: "operate", title: "@Resources.Operate", align: "center", width: 150,
						formatter: function(value, rec) {
							var strInfo = "";
							var tmp = rec.subject == null ? "" : rec.subject.replace(new RegExp("'",'g'),"’").replace(new RegExp('"','g'),"“");
							@if ((User as ICISPrincipal).IsSSA || (User as ICISPrincipal).CSAList.Contains(Model.ConferenceId) || Utility.HasConferenceRole((User as ICISPrincipal), Model.ConferenceId, ConstValues.FunctionId.ConferenceMail, RoleType.修改))
							{
								<text>
								strInfo += "<a href='#' style='color:#66CDAA;font-weight:bold;text-decoration:underline;' onclick='editData(\""
									+ rec.id + "\")'>@Resources.Modify</a>";
								</text>
							}
							return strInfo;
						}
					},
					</text>
				}
				{ field: "subject", title: "@Resources.MailSubject", align: "center", sortable: true, width: 200 },
				{ field: "mailType", title: "@Resources.MailType", align: "center", sortable: true, width: 150 },
				{ field: "mail", title: "@Resources.Mail", align: "center", sortable: true, width: 250 },
			]],
			onBeforeLoad: function(param) {
				param.conferenceId = $("#hidConferenceId").val();
				param.random = Math.random();
			}
		});

		$(window).resize(function () {
			$("#dataGrid").datagrid("resize", {
				width: $(window).width() - 285,
				height: $(window).height() - 123
			});
		});

		$("#detailWindow").window({
			onOpen: function () {
				$(this).scrollTop(0);
			},
			height: 800,
			top: 100
		});
	});

	function editData(id) {
		var url = "@Url.Action(nameof(ConferenceMailController.GetEditData),
				nameof(ConferenceMailController).GetControllerName())" + "?ConferenceId=" + $("#hidConferenceId").val() + "&MailId=" + id;
		$.get(url, null, function (data, textStatus, jqXHR) {
			if (data.result == "@ConstValues.AjaxFailResult") {
				common.showError(data.message);
				$("#dataGrid").datagrid("reload");
			} else {
				$("#hidId").val(id);
				$("#ctnForm").html("");
				$("#ctnForm").append("<div id='content' style='height:240px;overflow-y: auto;'></div>");
				$("#content").append(data.data.content);
				CKEDITOR.instances.editor.setData(data.data.customDefinition);
				$("#detailWindow").window("open");
			}
		});
	}

	function saveData() {
		var isValid = $("#frmDetail").form("validate");

		if (isValid) {
			$.messager.confirm("@Resources.Save", "@Resources.CfmSave", function (r) {
				if (r) {
					var loading = layer.load(0,  {
						shade: [0.4,"#fff"]
					});

					$("#frmDetail").form({
						iframe: false,
						success: function (data) { }
					});
					
					$("#txtCustomDefinition").val(CKEDITOR.instances.editor.getData());
					$("#frmDetail").form("submit", {
						url: "@Url.Action(nameof(ConferenceMailController.Modify), nameof(ConferenceMailController).GetControllerName(),
								new { ConferenceId = Model.ConferenceId })",
						onSubmit: function (param) {
							param.random = Math.random();
						},
						success: function (data) {
							layer.close(loading);
							data = JSON.parse(data);
							if (data.result == "@ConstValues.AjaxFailResult") {
								common.showError(data.message);
							} else {
								common.showSuccess(data.message, true);
								$("#detailWindow").window("close");
								$("#dataGrid").datagrid("reload");
							}
						}
					});
				}
			})
		}
	};
</script>
}